package service.impl;

import java.util.Map;

import dao.BookDao;
import entity.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.BookService;
import util.PageBean;

@Service("bookService")
public class BookServiceImpl implements BookService {

	@Autowired
	private BookDao bookDao;
	public void setBookDao(BookDao bookDao) {
		this.bookDao = bookDao;
	}

	public PageBean<Book> findPage(Map<String, Object> condition) {
		Integer pageSize = (Integer) condition.get("pageSize");
		Integer pageIndex = (Integer) condition.get("pageIndex");
		PageBean<Book> pageBean = new PageBean<Book>(pageSize,
				pageIndex, bookDao.findCount(condition));
		condition.put("start", (pageBean.getPageIndex()-1)*pageSize);
		condition.put("pageSize", pageBean.getPageSize());
		pageBean.setList(bookDao.findPage(condition));
		return pageBean;
	}

	public Book findById(Integer id) {
		
		return bookDao.findById(id);
	}

	public int save(Book book) {
		return bookDao.save(book);
	}

	public int update(Book book) {
		
		return bookDao.update(book);
	}

	public int remove(Integer id) {
		
		return bookDao.remove(id);
	}

}
